const path = require("path")
const HtmlWebpackPlugins = require("html-webpack-plugin")
const TestPlugin = require("./plugins/test-plugin")
const BannerWebpackPlugin = require("./plugins/banner-webpack-plugin")
const CleanWebpackPlugin = require("./plugins/clean-webpack-plugin")
const AnalyzeWebpackPlugin = require("./plugins/analyze-webpack-plugin")

module.exports = {
    entry: "./js/main.js",
    output: {
        path: path.resolve(__dirname,"dist"),
        filename: "js/[name].[hash:10].js",
        clean: false,
        assetModuleFilename: "asset/[name].[hash:10][ext]"
    },
    module: {
        rules: [
            // {
            //     test: /\.js$/,
            //     loader: "./loader/test-loader.js"
            // }
            // {
            //     test:/\.js$/,
            //     use: [
            //         "./loader/async/loader1.js",
            //         "./loader/async/loader2.js",
            //     ]
            // }
            // {
            //     test: /\.js$/,
            //     loader: "./loader/raw/raw-loader.js"
            // }
            // {
            //     test:/\.js$/,
            //     use:[
            //         "./loader/pitch/pitch1.js",
            //         "./loader/pitch/pitch2.js",
            //         "./loader/pitch/pitch3.js",
            //     ]
            // }
            {
                test:/\.js$/,
                loader: "./loader/clear-log-loader.js",
                options: {
                    enable:true,
                }
            },
            {
                test:/\.js$/,
                loader: "./loader/babel-loader.js",
                options: {
                    presets:["@babel/preset-env"],
                }
            },
            {
                test:/\.css$/,
                use: ["style-loader","css-loader"]
            },
            {
                test:/\.(png|jpg)$/,
                loader: "./loader/file-loader.js",
                type:"javascript/auto" // 阻止默认的asset打包配置
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugins({
            template:path.resolve(__dirname,"./src/index.html")
        }),
        // new TestPlugin()
        new BannerWebpackPlugin({
            auther:"SongZX"
        }),
        new CleanWebpackPlugin(),
        new AnalyzeWebpackPlugin()
    ],
    mode: "production"
}
